package soko.sokoban;

import java.util.ArrayList;

/**
 * An ArrayList of Tiles.
 */
public class Tiles extends ArrayList<Tile> {

	/**
	 * Gets the Tile on a particular coordinate.
	 *
	 * @param x the x-coordinate.
	 * @param y the y-coordinate.
	 * @return the Tile on a particular coordinate.
	 */
	public Tile getTile(int x, int y) {

		Tile result = null;

		for (Tile tile : this) {
			if (tile.getX() == x && tile.getY() == y) {
				result = tile;
				break;
			}
		}

		return result;
	}

	/**
	 * Returns the on which there is a man in the initial state.
	 * @return the Tile.
	 */
	public Tile getMan() {
		for (Tile tile : this) {
			if (tile.isMan()) {
				return tile;
			}
		}

		throw new RuntimeException("There should be a man.");
	}
}